package leetcode.offer_two_special.array;

/**
 * @author mazouri
 * @create 2021-09-05 18:19
 */
public class _12_pivotIndex {
    public int pivotIndex(int[] nums) {
        int sum = 0;
        int total = 0;
        for (int num : nums) total += num;

        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            if (sum-nums[i] == total-sum) return i;
        }
        return -1;
    }
}
